{extend name="base/base" /}
{block name="main"}
<form id="form" method="post" class="layui-form layui-form-pane" action="{:url('/admin/categoryEdit')}">
    <div class="layui-form-item">
        <label class="layui-form-label">名称</label>
        <div class="layui-input-block">
            <input type="text" name="name" placeholder="请输入" autocomplete="off" class="layui-input"
                   value="{:isset($list.name)? $list.name:''}"
             / >
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">描述</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入内容" class="layui-textarea" name="describe">{:isset($list.describe)? $list.describe:''}</textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
       {:token()}
            <input type="hidden" name="id" value="{:isset($list.id)? $list.id : ''}">
            <button class="layui-btn" lay-submit lay-filter="*">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
{/block}
{block name="script"}
{css href="/form-select/formSelects-v4.css" /}
<script>
    // layui.config({
    //     base: '/form-select/' //此处路径请自行处理, 可以使用绝对路径
    // }).extend({
    //     formSelects: 'formSelects-v4'
    // });
    layui.use(['form', 'jquery'], function () {
      var form = layui.form, $ = layui.jquery;

        //表单验证
        // form.verify({
        //     username: function (value, item) { //value：表单的值、item：表单的DOM对象
        //         var msg;
        //         $.ajax({
        //             async: false,
        //             url: "{:url('/admin/check')}",
        //             data: {username: value},
        //             success: function (data) {
        //                 if (data.code) {
        //                     msg = data.msg;
        //                 }
        //             }
        //         });
        //         return msg;
        //     },
        //     password:function(value, item){
        //         if(value){
        //             if(!(/^[\w\W]{6,25}$/.test(value))){
        //                 return '用户名不能全为数字';
        //             }
        //         }
        //     }
        // });
        // //表单提交
        form.on("submit(*)", function (data) {
            console.log(data);
            var obj = $(this);
            obj.attr("disabled", "disabled").addClass("layui-disabled");
            $.post(data.form.action, data.field, function (data) {
                var icon = 5;
                if (data.code) {
                    icon = 6;
                }
                layer.msg(data.msg, {icon: icon, time: 1500}, function () {   //提示的插件，可以使用alert代替
                    if (data.code) {
                        setTimeout(function () {
                            //刷新父页面
                            parent.location.reload();
                        }, 500);
                    } else {
                        $('#token').val(data.data.token);
                        obj.removeAttr("disabled").removeClass("layui-disabled");
                    }
                });
            }, 'json');
            return false;
        });
    });


</script>
{/block}